home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / qmenu / mtst.c < prev    next >
C/C++ Source or Header  |  1989-03-08  |  5KB  |  290 lines

  1. /*
  2.  * Example program for using quick menu package.  Contains the necessary
  3.  * declarations for a simple menu strip which it creates and destroys after
  4.  * letting the user play with it.
  5.  */
  6. #include <intuition/intuition.h>
  7. #include "qmenu.h"
  8.  
  9.  
  10. #define NILSUB    {NULL,NULL}
  11.  
  12. /*
  13.  * String arrays get defined in sort-of reverse order.
  14.  * I.e. the subitems get defined before the parent items.
  15.  * (One rule is that menu items that cause a Requester to
  16.  * appear are followed by "...".)
  17.  * The string arrays themselves are terminated by a null 
  18.  * string pointer.
  19.  */
  20. char *mpo_str[] = {
  21.     "!=ORaw Text...",
  22.     "Processed Text...",
  23.     "Drawing...",
  24.     "Picture...",
  25.     "Old Settings...",
  26.     NULL };
  27.  
  28. char *mps_str[] = {
  29.     "!=TText...",
  30.     "!=DDrawing...",
  31.     "Picture...",
  32.     NULL };
  33.  
  34. char *mp_str[] = {
  35.     "!=NNew...",
  36.     "Open",
  37.     "!=SSave...",
  38.     "Save as",
  39.     "Print...",
  40.     "Save Settings",
  41.     "About...",
  42.     "-",
  43.     "!bQuit...",
  44.     NULL };
  45.  
  46. /* Array of NewMenu structs to go with the above text items.
  47.  * Needs to be a one-to-one correspondence between text items
  48.  * (not rules) and NewMenu structs.
  49.  */
  50. struct NewMenu mp_sub[] = {
  51.     NILSUB,
  52.     { mpo_str, NULL },
  53.     NILSUB,
  54.     { mps_str, NULL },
  55.     NILSUB,
  56.     NILSUB,
  57.     NILSUB,
  58.     NILSUB
  59. };
  60.  
  61. char *mes_str[] = {
  62.     "!+!0111!=PPlain",
  63.     "!c!1!=BBold",
  64.     "!c!1!=IItalic",
  65.     "!c!1!=UUnderline",
  66.     NULL };
  67.  
  68. char *me_str[] = {
  69.     "!=QUndo",
  70.     "-",
  71.     "!=ZDelete",
  72.     "!=XCut",
  73.     "!=CCopy",
  74.     "!=VPaste",
  75.     "-",
  76.     "Set Font...",
  77.     "Set Style",
  78.     NULL };
  79.  
  80. struct NewMenu me_sub[] = {
  81.     NILSUB,
  82.     NILSUB,
  83.     NILSUB,
  84.     NILSUB,
  85.     NILSUB,
  86.     NILSUB,
  87.     { mes_str, NULL }
  88. };
  89.  
  90. char *mdz_str[] = {
  91.     "!=>In",
  92.     "!=<Out",
  93.     "!=MManual",
  94.     NULL };
  95.  
  96. char *mdv_str[] = {
  97.     "!+!tText",
  98.     "!+!tLines",
  99.     "!+!tImages",
  100.     "!+!tBoxes",
  101.     "!+!tLabels",
  102.     NULL };
  103.  
  104. char *mds_str[] = {
  105.     "Interlace",
  106.     "Non-interlace",
  107.     "Workbench",
  108.     NULL };
  109.  
  110. char *md_str[] = { 
  111.     "Zoom",
  112.     "!=AAuto Scale",
  113.     "-",
  114.     "!c!tCoordinates",
  115.     "Visible",
  116.     "-",
  117.     "Screen Colors...",
  118.     "Screen Type",
  119.     NULL };
  120.  
  121. struct NewMenu md_sub[] = {
  122.     { mdz_str, NULL },
  123.     NILSUB,
  124.     NILSUB,
  125.     { mdv_str, NULL },
  126.     NILSUB,
  127.     { mds_str, NULL }
  128. };
  129.  
  130. char *mhc_str[] = {
  131.     "Plot...",
  132.     "Set...",
  133.     "Lay in...",
  134.     NULL };
  135.  
  136. char *mhw_str[] = {
  137.     "!+!0111111Full Impulse",
  138.     "!c!1011111!=1Warp 1",
  139.     "!c!1101111!=2Warp 2",
  140.     "!c!1110111!=3Warp 3",
  141.     "!c!1111011!=4Warp 4",
  142.     "!c!1111101!=5Warp 5",
  143.     "!c!1111110Space Normal",
  144.     NULL };
  145.  
  146. char *mhp_str[] = {
  147.     "Stun",
  148.     "Kill",
  149.     "Maim",
  150.     "Burn",
  151.     "Overload",
  152.     "Ineffective",
  153.     "Burn Out",
  154.     NULL };
  155.  
  156. char *mh_str[] = {
  157.     "New Course",
  158.     "Speed",
  159.     "Standard Orbit",
  160.     "Tractor Beam...",
  161.     "Lock Phasers",
  162.     "-",
  163.     "\"Make It So.\"",
  164.     NULL };
  165.  
  166. struct NewMenu mh_sub[] = {
  167.     { mhc_str, NULL },
  168.     { mhw_str, NULL },
  169.     NILSUB,
  170.     NILSUB,
  171.     { mhp_str, NULL },
  172.     NILSUB
  173. };
  174.  
  175. char *mt_str[] = {
  176.     "Hammer",
  177.     "Screwdriver",
  178.     "Chisel",
  179.     "Knife",
  180.     "Felt Pen",
  181.     "Air Freshener",
  182.     "-",
  183.     "Hammer Size...",
  184.     "Screw Type...",
  185.     "Pine Scent...",
  186.     NULL };
  187.  
  188. char *mm_str[] = {
  189.     "Rotate...",
  190.     "Spin...",
  191.     "Turn Around...",
  192.     "Flip Out...",
  193.     "Randomize...",
  194.     "Energize...",
  195.     "Simplify",
  196.     "Complexify",
  197.     NULL };
  198.  
  199. char *main_str[] = {
  200.     "Project",
  201.     "Edit",
  202.     "Display",
  203.     "Tools",
  204.     "Helm",
  205.     "Modify",
  206.     NULL };
  207.  
  208. struct NewMenu main_sub[] = {
  209.     { mp_str, mp_sub },
  210.     { me_str, me_sub },
  211.     { md_str, md_sub },
  212.     { mt_str, NULL },
  213.     { mh_str, mh_sub },
  214.     { mm_str, NULL }
  215. };
  216.  
  217. struct NewMenu main_menu = { main_str, main_sub };
  218.  
  219. struct TextAttr ta = { (UBYTE*) "topaz.font", 8,0,0 };
  220.  
  221.  
  222. /* Basic stuff for the test program.
  223.  */
  224. struct NewWindow nwin = {
  225.     50,20, 200,100, -1,-1, CLOSEWINDOW,
  226.     WINDOWCLOSE|WINDOWDRAG|ACTIVATE,
  227.     NULL,NULL, (UBYTE*) "Test the Menus", NULL,NULL,
  228.     0,0,0,0, WBENCHSCREEN
  229. };
  230.  
  231. #define OLIB(var,nam)    (var=OpenLibrary(nam,33L))
  232.  
  233. struct IntuitionBase *IntuitionBase;
  234. struct Window *mywin;
  235.  
  236.  
  237. struct Window *OpenWindow();
  238. void *OpenLibrary();
  239. void *GetMsg();
  240.  
  241.  
  242. main ()
  243. {
  244.     if (OLIB(IntuitionBase,"intuition.library")) {
  245.         if (mywin = OpenWindow (&nwin)) {
  246.             Body ();
  247.             CloseWindow (mywin);
  248.         }
  249.         CloseLibrary (IntuitionBase);
  250.     }
  251. }
  252.  
  253.  
  254. Body ()
  255. {
  256.     struct IntuiMessage *im;
  257.     struct Menu *m;
  258.  
  259.     if (!(m = GenMenu (&main_menu))) return;
  260.  
  261.     SetMenuStrip (mywin, m);
  262.  
  263.     /* Wait for the close window message.
  264.      */
  265.     while (!(im = (struct IntuiMessage *) GetMsg (mywin->UserPort)))
  266.         WaitPort (mywin->UserPort);
  267.     ReplyMsg (im);
  268.  
  269.     ReadMenuState (m);
  270.     ClearMenuStrip (mywin);
  271.     FreeMenu (m);
  272. }
  273.  
  274.  
  275. ReadMenuState (m)
  276.     struct Menu *m;
  277. {
  278.     struct MenuItem    *mi;
  279.  
  280.     /* Get the text style menu array and test for checkmarks.
  281.      */
  282.     mi = m[1].FirstItem[8].SubItem;
  283.     printf ("Text Style: ");
  284.     if (mi[0].Flags & CHECKED) printf ("Plain");
  285.     if (mi[1].Flags & CHECKED) printf ("Bold ");
  286.     if (mi[2].Flags & CHECKED) printf ("Italic ");
  287.     if (mi[3].Flags & CHECKED) printf ("Underline");
  288.     printf ("\n");
  289. }
  290.